import { isLocal } from '@/env'

export const BackGroundMixin = {
  computed: {
    assetMap () {
      return this.$store.state.assetMap
    },
    backgroundUrl () {
      return function (imageUrl, isNetwork = false) {
        let url = ''
        if (isNetwork) {
          url = imageUrl
        } else if (isLocal()) {
          url = process.env.LOCAL_SERVER + '/static/' + imageUrl
        } else {
          url = !this.assetMap || !this.assetMap[imageUrl] ? '' : this.assetMap[imageUrl].replace(/\\/g, '/')
        }
        return `url(${url})`
      }
    }
  },
  methods: {
    mapAssetUrl (imageUrl) {
      if (isLocal()) {
        return process.env.LOCAL_SERVER + '/static/' + imageUrl
      } else {
        return !this.assetMap || !this.assetMap[imageUrl] ? '' : this.assetMap[imageUrl].replace(/\\/g, '/')
      }
    }
  }
}
